package net.mcreator.infinite_storage.procedure;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.Entity;

import net.mcreator.infinite_storage.InfiniteStorage;
import net.mcreator.infinite_storage.ElementsInfiniteStorageMod;

import java.util.Map;
import java.util.HashMap;

import java.io.File;

@ElementsInfiniteStorageMod.ModElement.Tag
public class ProcedureInfiniteBagInit extends ElementsInfiniteStorageMod.ModElement {
	public ProcedureInfiniteBagInit(ElementsInfiniteStorageMod instance) {
		super(instance, 55);
	}
	static Map<String, Object> $_dependencies = new HashMap<>();
	public static void executeProcedure(Map<String, Object> dependencies) {
		if (dependencies.get("entity") == null) {
			return;
		}
		Entity entity = (Entity) dependencies.get("entity");
		File configFile = new File("config/InfiniteStorage.cfg");
		InfiniteStorage InfiniteStorage = new InfiniteStorage();
		InfiniteStorage.init(configFile);
		NBTTagCompound InfiniteBag = entity.getEntityData().getCompoundTag("InfiniteBag");
		int LevelTemp = ((entity instanceof EntityPlayer) ? ((EntityPlayer) entity).experienceLevel : 0);
		InfiniteBag.setBoolean("bagState", InfiniteStorage.bagState);
		InfiniteBag.setDouble("needLevel", InfiniteStorage.needLevel);
		InfiniteBag.setDouble("guiModel", InfiniteStorage.guiModel);
		if ((InfiniteBag.getDouble("InfiniteBagPageAdd") <= 0)) {
			InfiniteBag.setDouble("InfiniteBagPageAdd", 0);
		}
		if ((InfiniteBag.getDouble("InfiniteBagPage") <= 0)) {
			InfiniteBag.setDouble("InfiniteBagPage", 0);
		}
		if ((!InfiniteBag.getBoolean("bagState"))) {
			InfiniteBag.setDouble("InfiniteBagPageAdd", (LevelTemp / 3));
		} else if (((entity.getEntityData().hasKey("InfiniteBagPageAdd") ? entity.getEntityData().getDouble("InfiniteBagPageAdd") : 0) > 0)) {
			InfiniteBag.setDouble("InfiniteBagPageAdd",
					(entity.getEntityData().hasKey("InfiniteBagPageAdd") ? entity.getEntityData().getDouble("InfiniteBagPageAdd") : 0));
			entity.getEntityData().setDouble("InfiniteBagPageAdd", 0);
		}
		entity.getEntityData().setTag("InfiniteBag", InfiniteBag);
	}
}
